package com.demo.controller;

import java.util.ArrayList;
import java.util.List;

import com.demo.constant.ErrorInfo;
import com.demo.dto.OrderCondition;
import com.demo.dto.QueryCondition;
import com.demo.dto.ReturenJson;
import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;
import com.jfinal.plugin.activerecord.Record;

public class BaseController extends Controller {

	protected List<QueryCondition> conditionList = new ArrayList<QueryCondition>();
	protected List<OrderCondition> orderConditionList = new ArrayList<OrderCondition>();
	protected Record record = new Record();
	
	public void renderDataJson(String errCode, Object data) {
		String msg = ErrorInfo.getErrMsg(errCode);
		ReturenJson bean = new ReturenJson(errCode, msg, data);
		String callback = getPara("callback");
		if (null == callback || "".equals(callback)) {
			renderJson(bean);
		}else {
			String jsonp = callback + "("+ JsonKit.toJson(bean)+ ")";
			renderJson(jsonp);
		}
	}
	
	public void renderDataJson(String errCode){
		renderDataJson(errCode, null);
	}
}
